package com.p2p.account.controller;

import com.p2p.account.service.AgentLogService;
import com.p2p.account.vo.AgentLogCondition;
import com.p2p.account.vo.AgentLogResult;
import com.p2p.common.base.BaseController;
import com.p2p.common.utils.StringUtils;
import com.p2p.common.utils.Underline2Camel;
import com.p2p.terminal.vo.MacErrorCondition;
import com.p2p.terminal.vo.MacErrorResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Allen on 2017/3/19.
 */
@RestController
@RequestMapping(value = "agentLog")
public class AgentLogController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(AgentLogController.class);
    @Autowired
    private AgentLogService agentLogService;

    /**
     * 获取分组列表
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "selectP2pMac", method = RequestMethod.GET)
    public Map selectP2pMac(HttpServletRequest request) {
        String startDate = request.getParameter("startDate");
        String endDate = request.getParameter("endDate");
        String agentCode = request.getParameter("agentCode").equals("0") ? null : request.getParameter("agentCode");


        Integer pageIndex = Integer.parseInt(request.getParameter("pageIndex"));
        Integer pageSize = Integer.parseInt(request.getParameter("pageSize"));
        String sortField = Underline2Camel.camel2Underline(request.getParameter("sort") == null ? "id" : request.getParameter("sort"), true);
        String orderField = request.getParameter("order") == null ? "desc" : request.getParameter("order");
        int startRow = (pageIndex - 1) * pageSize;

        AgentLogCondition agentLogCondition = new AgentLogCondition();
        agentLogCondition.setStartDate(startDate);
        agentLogCondition.setEndDate(endDate);
        agentLogCondition.setAgentCode(agentCode);
        agentLogCondition.setStartRow(startRow);
        agentLogCondition.setPageSize(pageSize);
        agentLogCondition.setSortField(sortField);
        agentLogCondition.setOrderField(orderField);

        AgentLogResult agentLogResult = agentLogService.selectAgentLog(agentLogCondition);
        Map result = new HashMap();
        result.put("rel", true);
        result.put("msg", "SUCCESS");
        result.put("list", agentLogResult.getAgentLogList());
        result.put("count", agentLogResult.getSize());
        return result;
    }
}
